
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using System.Drawing;

namespace ePlanSysOman
{
    public class frmConnection : DevExpress.XtraEditors.XtraForm
    {
        int iSec = 0;
        internal System.Windows.Forms.Panel pnlConnection;
        internal System.Windows.Forms.Label label3;
        internal System.Windows.Forms.PictureBox pictureBox2;
        internal System.Windows.Forms.PictureBox pictureBox1;
        internal DevExpress.XtraEditors.MarqueeProgressBarControl MarqueeProgressBarControl;
        internal System.Windows.Forms.Panel pnlLogin;
        internal DevExpress.XtraEditors.SimpleButton cmdLogin;
        internal DevExpress.XtraEditors.SimpleButton cmdExit;
        internal DevExpress.XtraEditors.TextEdit tx_password;
        internal DevExpress.XtraEditors.TextEdit tx_user;
        internal System.Windows.Forms.Label label2;
        internal System.Windows.Forms.Label Label5;
        private DevExpress.XtraEditors.SimpleButton withEventsField_SimpleButton1;
        internal DevExpress.XtraEditors.SimpleButton SimpleButton1
        {
            get { return withEventsField_SimpleButton1; }
            set
            {
                if (withEventsField_SimpleButton1 != null)
                {
                    withEventsField_SimpleButton1.Click -= SimpleButton1_Click;
                }
                withEventsField_SimpleButton1 = value;
                if (withEventsField_SimpleButton1 != null)
                {
                    withEventsField_SimpleButton1.Click += SimpleButton1_Click;
                }
            }
        }
        internal System.Windows.Forms.Label Label1;
        internal System.Windows.Forms.PictureBox PictureBox3;
        private System.Windows.Forms.Label withEventsField_Label4;
        internal System.Windows.Forms.Label Label4
        {
            get { return withEventsField_Label4; }
            set
            {
                if (withEventsField_Label4 != null)
                {
                    withEventsField_Label4.Click -= Label4_Click;
                }
                withEventsField_Label4 = value;
                if (withEventsField_Label4 != null)
                {
                    withEventsField_Label4.Click += Label4_Click;
                }
            }
        }
        internal System.Windows.Forms.Label Label6;
        private Button button1;
        private Label label4;

        bool bIsConnected;
        #region " Windows Form Designer generated code "

        public frmConnection()
        {
            KeyDown += frmConnection_KeyDown;
            //This call is required by the Windows Form Designer.
            InitializeComponent();
            //AddHandler tx_user.GotFocus, AddressOf Control_Focus
            //AddHandler tx_password.GotFocus, AddressOf Control_Focus
            //AddHandler tx_password.LostFocus, AddressOf Control_LostFocus
            //AddHandler tx_user.LostFocus, AddressOf Control_LostFocus

            //Me.LookAndFeel.SkinName = Ap.MySkinName
            //Me.LookAndFeel.UseWindowsXPTheme = Ap.MyUseWindowsXPTheme
            //DevExpress.LookAndFeel.LookAndFeelHelper.ForceDefaultLookAndFeelChanged()
            //Me.BackColor = Ap.MySkinColor
        }

        
        //Form overrides dispose to clean up the component list.
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if ((components != null))
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }
        internal DevExpress.XtraEditors.PanelControl PanelControl1;
        private System.Windows.Forms.Timer withEventsField_Timer;
        internal System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
        //Required by the Windows Form Designer

        private System.ComponentModel.IContainer components;
        //NOTE: The following procedure is required by the Windows Form Designer
        //It can be modified using the Windows Form Designer.  
        //Do not modify it using the code editor.
        [System.Diagnostics.DebuggerStepThrough()]
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmConnection));
            this.PanelControl1 = new DevExpress.XtraEditors.PanelControl();
            this.label4 = new System.Windows.Forms.Label();
            this.button1 = new System.Windows.Forms.Button();
            this.Label6 = new System.Windows.Forms.Label();
            this.Label1 = new System.Windows.Forms.Label();
            this.PictureBox3 = new System.Windows.Forms.PictureBox();
            this.pnlConnection = new System.Windows.Forms.Panel();
            this.label3 = new System.Windows.Forms.Label();
            this.pictureBox2 = new System.Windows.Forms.PictureBox();
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            this.MarqueeProgressBarControl = new DevExpress.XtraEditors.MarqueeProgressBarControl();
            this.pnlLogin = new System.Windows.Forms.Panel();
            this.cmdLogin = new DevExpress.XtraEditors.SimpleButton();
            this.cmdExit = new DevExpress.XtraEditors.SimpleButton();
            this.tx_password = new DevExpress.XtraEditors.TextEdit();
            this.tx_user = new DevExpress.XtraEditors.TextEdit();
            this.label2 = new System.Windows.Forms.Label();
            this.Label5 = new System.Windows.Forms.Label();
            this.timer1 = new System.Windows.Forms.Timer(this.components);
            ((System.ComponentModel.ISupportInitialize)(this.PanelControl1)).BeginInit();
            this.PanelControl1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.PictureBox3)).BeginInit();
            this.pnlConnection.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.MarqueeProgressBarControl.Properties)).BeginInit();
            this.pnlLogin.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.tx_password.Properties)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.tx_user.Properties)).BeginInit();
            this.SuspendLayout();
            // 
            // PanelControl1
            // 
            this.PanelControl1.Controls.Add(this.label4);
            this.PanelControl1.Controls.Add(this.button1);
            this.PanelControl1.Controls.Add(this.Label6);
            this.PanelControl1.Controls.Add(this.Label1);
            this.PanelControl1.Controls.Add(this.PictureBox3);
            this.PanelControl1.Controls.Add(this.pnlConnection);
            this.PanelControl1.Controls.Add(this.pnlLogin);
            this.PanelControl1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.PanelControl1.Location = new System.Drawing.Point(0, 0);
            this.PanelControl1.LookAndFeel.SkinName = "Money Twins";
            this.PanelControl1.Name = "PanelControl1";
            this.PanelControl1.Size = new System.Drawing.Size(607, 220);
            this.PanelControl1.TabIndex = 0;
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Font = new System.Drawing.Font("Palatino Linotype", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label4.Location = new System.Drawing.Point(361, 9);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(142, 26);
            this.label4.TabIndex = 65;
            this.label4.Text = "ePlanSys Oman";
            this.label4.Click += new System.EventHandler(this.Label4_Click);
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(516, 178);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(73, 30);
            this.button1.TabIndex = 69;
            this.button1.Text = "Exit";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.SimpleButton1_Click);
            // 
            // Label6
            // 
            this.Label6.AutoSize = true;
            this.Label6.BackColor = System.Drawing.Color.Transparent;
            this.Label6.Font = new System.Drawing.Font("Lucida Handwriting", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Label6.Location = new System.Drawing.Point(466, 30);
            this.Label6.Name = "Label6";
            this.Label6.Size = new System.Drawing.Size(0, 21);
            this.Label6.TabIndex = 68;
            // 
            // Label1
            // 
            this.Label1.AutoSize = true;
            this.Label1.BackColor = System.Drawing.Color.White;
            this.Label1.Font = new System.Drawing.Font("Lucida Handwriting", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Label1.Location = new System.Drawing.Point(27, 169);
            this.Label1.Name = "Label1";
            this.Label1.Size = new System.Drawing.Size(177, 17);
            this.Label1.TabIndex = 67;
            this.Label1.Text = "Planning the Future";
            // 
            // PictureBox3
            // 
            this.PictureBox3.BackColor = System.Drawing.Color.Transparent;
            this.PictureBox3.ErrorImage = null;
            this.PictureBox3.Image = ((System.Drawing.Image)(resources.GetObject("PictureBox3.Image")));
            this.PictureBox3.Location = new System.Drawing.Point(5, 4);
            this.PictureBox3.Name = "PictureBox3";
            this.PictureBox3.Size = new System.Drawing.Size(215, 213);
            this.PictureBox3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.PictureBox3.TabIndex = 66;
            this.PictureBox3.TabStop = false;
            // 
            // pnlConnection
            // 
            this.pnlConnection.BackColor = System.Drawing.Color.Transparent;
            this.pnlConnection.Controls.Add(this.label3);
            this.pnlConnection.Controls.Add(this.pictureBox2);
            this.pnlConnection.Controls.Add(this.pictureBox1);
            this.pnlConnection.Controls.Add(this.MarqueeProgressBarControl);
            this.pnlConnection.Location = new System.Drawing.Point(245, 54);
            this.pnlConnection.Name = "pnlConnection";
            this.pnlConnection.Size = new System.Drawing.Size(318, 92);
            this.pnlConnection.TabIndex = 61;
            // 
            // label3
            // 
            this.label3.BackColor = System.Drawing.Color.Transparent;
            this.label3.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(161)));
            this.label3.ImeMode = System.Windows.Forms.ImeMode.NoControl;
            this.label3.Location = new System.Drawing.Point(50, 49);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(225, 33);
            this.label3.TabIndex = 15;
            this.label3.Text = "Compacting and Connecting to Database . . . . . ";
            this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // pictureBox2
            // 
            this.pictureBox2.Location = new System.Drawing.Point(281, 22);
            this.pictureBox2.Name = "pictureBox2";
            this.pictureBox2.Size = new System.Drawing.Size(32, 33);
            this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.pictureBox2.TabIndex = 14;
            this.pictureBox2.TabStop = false;
            // 
            // pictureBox1
            // 
            this.pictureBox1.BackColor = System.Drawing.Color.Transparent;
            this.pictureBox1.Location = new System.Drawing.Point(10, 22);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(32, 32);
            this.pictureBox1.TabIndex = 13;
            this.pictureBox1.TabStop = false;
            // 
            // MarqueeProgressBarControl
            // 
            this.MarqueeProgressBarControl.EditValue = 0;
            this.MarqueeProgressBarControl.Location = new System.Drawing.Point(53, 27);
            this.MarqueeProgressBarControl.Name = "MarqueeProgressBarControl";
            this.MarqueeProgressBarControl.Properties.EndColor = System.Drawing.SystemColors.GradientActiveCaption;
            this.MarqueeProgressBarControl.Size = new System.Drawing.Size(222, 19);
            this.MarqueeProgressBarControl.TabIndex = 16;
            // 
            // pnlLogin
            // 
            this.pnlLogin.BackColor = System.Drawing.Color.Transparent;
            this.pnlLogin.Controls.Add(this.cmdLogin);
            this.pnlLogin.Controls.Add(this.cmdExit);
            this.pnlLogin.Controls.Add(this.tx_password);
            this.pnlLogin.Controls.Add(this.tx_user);
            this.pnlLogin.Controls.Add(this.label2);
            this.pnlLogin.Controls.Add(this.Label5);
            this.pnlLogin.Location = new System.Drawing.Point(255, 51);
            this.pnlLogin.Name = "pnlLogin";
            this.pnlLogin.Size = new System.Drawing.Size(334, 106);
            this.pnlLogin.TabIndex = 60;
            this.pnlLogin.Visible = false;
            // 
            // cmdLogin
            // 
            this.cmdLogin.ImageIndex = 0;
            this.cmdLogin.Location = new System.Drawing.Point(50, 78);
            this.cmdLogin.LookAndFeel.SkinName = "Lilian";
            this.cmdLogin.Name = "cmdLogin";
            this.cmdLogin.Size = new System.Drawing.Size(100, 25);
            this.cmdLogin.TabIndex = 2;
            this.cmdLogin.Text = "Áðïäï÷Þ";
            this.cmdLogin.Click += new System.EventHandler(this.cmdLogin_Click);
            // 
            // cmdExit
            // 
            this.cmdExit.Location = new System.Drawing.Point(178, 78);
            this.cmdExit.Name = "cmdExit";
            this.cmdExit.Size = new System.Drawing.Size(100, 25);
            this.cmdExit.TabIndex = 3;
            this.cmdExit.Text = "¸îïäïò";
            this.cmdExit.Click += new System.EventHandler(this.cmdExit_Click);
            // 
            // tx_password
            // 
            this.tx_password.EditValue = "";
            this.tx_password.ImeMode = System.Windows.Forms.ImeMode.NoControl;
            this.tx_password.Location = new System.Drawing.Point(136, 41);
            this.tx_password.Name = "tx_password";
            this.tx_password.Properties.Appearance.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold);
            this.tx_password.Properties.Appearance.Options.UseFont = true;
            this.tx_password.Size = new System.Drawing.Size(112, 20);
            this.tx_password.TabIndex = 1;
            // 
            // tx_user
            // 
            this.tx_user.EditValue = "";
            this.tx_user.Location = new System.Drawing.Point(136, 13);
            this.tx_user.Name = "tx_user";
            this.tx_user.Properties.Appearance.BackColor = System.Drawing.SystemColors.Window;
            this.tx_user.Properties.Appearance.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(161)));
            this.tx_user.Properties.Appearance.Options.UseBackColor = true;
            this.tx_user.Properties.Appearance.Options.UseFont = true;
            this.tx_user.Size = new System.Drawing.Size(112, 20);
            this.tx_user.TabIndex = 0;
            // 
            // label2
            // 
            this.label2.BackColor = System.Drawing.Color.Transparent;
            this.label2.ImeMode = System.Windows.Forms.ImeMode.NoControl;
            this.label2.Location = new System.Drawing.Point(48, 43);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(92, 19);
            this.label2.TabIndex = 57;
            this.label2.Text = "Êùäéêüò . . . . . . . . .";
            // 
            // Label5
            // 
            this.Label5.BackColor = System.Drawing.Color.Transparent;
            this.Label5.ImeMode = System.Windows.Forms.ImeMode.NoControl;
            this.Label5.Location = new System.Drawing.Point(46, 15);
            this.Label5.Name = "Label5";
            this.Label5.Size = new System.Drawing.Size(96, 22);
            this.Label5.TabIndex = 56;
            this.Label5.Text = "¼íïìá ×ñÞóôç . . . . . . .";
            // 
            // timer1
            // 
            this.timer1.Enabled = true;
            this.timer1.Interval = 200;
            this.timer1.Tick += new System.EventHandler(this.Timer_Tick);
            // 
            // frmConnection
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
            this.ClientSize = new System.Drawing.Size(607, 220);
            this.ControlBox = false;
            this.Controls.Add(this.PanelControl1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.KeyPreview = true;
            this.LookAndFeel.SkinName = "Money Twins";
            this.Name = "frmConnection";
            this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Connecting...";
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.frmConnection_KeyDown);
            ((System.ComponentModel.ISupportInitialize)(this.PanelControl1)).EndInit();
            this.PanelControl1.ResumeLayout(false);
            this.PanelControl1.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.PictureBox3)).EndInit();
            this.pnlConnection.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.MarqueeProgressBarControl.Properties)).EndInit();
            this.pnlLogin.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.tx_password.Properties)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.tx_user.Properties)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion        
        public bool ConnectToServer()
        {
            try
            {
                pnlConnection.Visible = true;
                timer1.Enabled = true;
                this.ShowDialog();

                return bIsConnected;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "General Error", MessageBoxButtons.OK);
                return !bIsConnected;
            }
        }

        private void frmConnection_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return)
            {
                cmdLogin_Click(sender, e);
            }
            else if (e.KeyCode == Keys.Escape)
            {
                cmdExit_Click(sender, e);
            }
        }
        private void cmdExit_Click(System.Object sender, System.EventArgs e)
    {        
        Module1.newModule.Cn.Close();
        Module1.newModule.Cn.Dispose();
        bIsConnected = false;
        this.Dispose();
    }

        private void cmdLogin_Click(System.Object sender, System.EventArgs e)
        {
            try
            {
                if (tx_user.Text.Length == 0)
                {
                    MessageBox.Show("Äåí Ý÷åôå äçëþóç ÷ñÞóôç ãéá ôçí åßóïäü óáò óôçí åöáñìïãÞ.", "Áêýñùóç åéóüäïõ...", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    tx_user.Focus();
                    return;
                }

                // Dim bLogin As Boolean = iLogin(tx_user.Text, IIf(tx_password.Text = "", myPassword, tx_password.Text))

                //If bLogin Then
                //    Me.Dispose()
                //Else
                //    xtramessagebox.show("ËÜèïò üíïìá ×ñÞóôç Þ êùäéêïý ðñüóâáóçò.", "Áêýñùóç åéóüäïõ...", MessageBoxButtons.OK, MessageBoxIcon.Stop)
                //    tx_user.Focus()
                //    tx_user.SelectAll()
                //End If

            }
            catch (Exception ex)
            {
                MessageBox.Show("ERROR", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        private void Control_Focus(object sender, System.EventArgs e)
        {
            //sender.BackColor = System.Drawing.Color.Yellow;
            //sender.refresh();
        }

        private void Control_LostFocus(object sender, System.EventArgs e)
        {
            //sender.BackColor = System.Drawing.SystemColors.Window;
        }

        private void Timer_Disposed(object sender, System.EventArgs e)
        {

        }


        private void Timer_Tick(object sender, System.EventArgs e)
        {
            Application.DoEvents();
            iSec += 1;
            if (iSec == 3)
            {
                timer1.Enabled = false;
                bIsConnected = Module1.newModule.InitConnection();
                timer1.Enabled = bIsConnected;
                if (!bIsConnected)
                {
                    timer1.Dispose();
                }
            }

            if (iSec == 3)
            {
                timer1.Dispose();
                this.Dispose();
            }
        }

        private void SimpleButton1_Click(System.Object sender, System.EventArgs e)
        {
            this.Dispose();
            Application.Exit();
        }


        private void Label4_Click(System.Object sender, System.EventArgs e)
        {
        }
    }
}

//=======================================================
//Service provided by Telerik (www.telerik.com)
//Conversion powered by NRefactory.
//Twitter: @telerik
//Facebook: facebook.com/telerik
//=======================================================
